<template>
	<view>
		<view class="info-box">
			<view class="info-each">
				<view class="">招聘标题</view>
				<view class="input" style="width: 70%;">
					<input style="width: 100%;" v-model="title" type="text" placeholder="请输入招聘岗位的具体职位名称" />
				</view>
			</view>
			<view class="wire"></view>
			<view class="info-each">
				<view class="">岗位选择</view>
				<fy-picker mode="multiSelector" range-key="name" v-model="data1Value" :range="range1" @confirm="onconfirm1">
				<view class="">
					<text class="tint">{{job_name || '请选择'}}</text>
					<image src="../../static/right-img.png" mode=""></image>
				</view>
				</fy-picker>
			</view>
			<view class="wire"></view>
			<view class="introduce-box">
				<view class="">职位描述</view>
				<view class="textarea-box">
					<textarea v-model="description" name="" id="" cols="30" rows="10" placeholder="请写明工作单位，具体工作内容，上班时间，年龄要求，福利待遇等信息"></textarea>
				</view>
			</view>
			<view class="wire"></view>
			<view class="info-each">
				<view class="">工作城市</view>
				<!-- <view class="input">
					<input v-model="county" type="text" placeholder="请输入" />
				</view> -->
				<view class="" @click="show = true">
					<text class="tint">{{county || '请选择'}}</text>
					<image src="../../static/right-img.png" mode=""></image>
				</view>
			</view>
			<view class="wire"></view>
			<view class="info-each">
				<view class="">薪资待遇</view>
				<view class="pay-box">
					<view class="origin">
						<input v-model="min_salary" type="number" placeholder="请输入"> <text>元/月 <text class="need">*</text> </text>
					</view>
					<view class="origin">
						<input v-model="max_salary" type="number" placeholder="请输入"> <text>元/月</text>
					</view>
				</view>
			</view>
		</view>
		
		<view class="info-box" style="margin-top: 24rpx">
			<view class="info-each">
				<view class="">联系人</view>
				<view class="input">
					<input v-model="name" type="text" placeholder="请输入" />
				</view>
			</view>
			<view class="wire"></view>
			<view class="info-each">
				<view class="">电话</view>
				<view class="input">
					<input v-model="mobile" type="number" placeholder="请输入" />
				</view>
			</view>
		</view>
		
		<view class="info-box" style="margin-top: 24rpx">
			<view class="info-each">
				<view class="">展示视频</view>
				<view class="">
					<!-- <text class="tint">请上传展示视频</text> -->
				</view>
			</view>
			<view style="color: #999999;font-size: 22rpx;padding-top: 5rpx;">视频不要求必须上传，视频上传后，将会在平台上展示，同时半柿团队会将视频发到视频平台上帮你免费宣传</view>
			<view class="upimg">
				<u-upload
					:fileList="fileList2"
					@afterRead="afterRead"
					@delete="deletePic"
					name="2"
					multiple
					:maxCount="1"
					accept="video"
				>
				<image src="../../static/imgs.png" mode="widthFix"
					style="width: 130rpx;height: 130rpx;">
				</image>
				</u-upload>
			</view>
		</view>
		
		<view class="info-box" style="margin-top: 24rpx">
			<view class="info-each">
				<view class="">视频库视频</view>
				<view class="">
					<!-- <text class="tint">请上传视频库视频</text> -->
				</view>
			</view>
			<view style="color: #999999;font-size: 22rpx;padding-top: 5rpx;">视视频库的视频，主要用于视频平台的宣传，一个视频只能发布一次，为了更好的宣传效果，你可以将同一个信息的视频，从不同的位置拍摄多个视频上传，由半柿平台免费帮你多次宣传，快速促进您信息的成交</view>
			<view class="upimg">
				<u-upload
					:fileList="fileList3"
					@afterRead="afterRead"
					@delete="deletePic"
					name="3"
					multiple
					:maxCount="6"
					accept="video"
				>
				<image src="../../static/imgs.png" mode="widthFix"
					style="width: 130rpx;height: 130rpx;">
				</image>
				</u-upload>
			</view>
		</view>

		<view class="cotton"></view>
		<view class="btn-box">
			<view class="btn" @click="issue" v-if="id">修改</view>
			<view class="btn" @click="issue" v-else>发布</view>
		</view>
		
		
		<TopPopup :show1="show2" :meal="meal" @padlock="padlock" @ckeck="ckeck"></TopPopup>
		
		<u-picker keyName="name" :show="show" ref="uPicker" :columns="cityList" @confirm="confirm" @change="changeHandler" @cancel="show = false"></u-picker>
		
		
		<view class="issue" @click="toVideo">
			拍摄教程
		</view>
	</view>
</template>

<script>
	import TopPopup from "@/components/topPopup.vue"
	import FyPicker from '@/components/fy-picker/fy-picker.vue'
export default {
	components: { FyPicker,TopPopup },
	data() {
		return {
			data1Value: [],
			range1: [],
			title:'',
			job_id:'',
			description:'',
			county:'',
			min_salary:'',
			max_salary:'',
			name:'',
			mobile:'',
			job_name:'',
			id:'',
			
			cityList:[],
			show: false,
			columnData: [],
			show2: false,
			config:uni.getStorageSync('config'),
			
			order_id:'',
			itemid:'',
			meal: [],
			current:null,
			
			myMoney:'',
			paytype:null,
			
			fileList2:[],//视频 单
			fileList3:[],//视频 多
		};
	},
	onLoad(op) {
		if(op.id){
			this.id = op.id
			this.gethouseDetail(op.id)
			uni.setNavigationBarTitle({
			  title:'招聘信息编辑'
			});
		}
		this.getjob()
		this.getcity()
		this.getcombo()
		this.getMoney()
		// #ifdef MP-WEIXIN
		this.paytype = 2
		// #endif
		// #ifdef APP
		this.paytype = 1
		// #endif
	},
	methods: {
		toVideo(){
			uni.navigateTo({
				url:'/pages/videoShopping/videoShopping?types=4'
			})
		},
		padlock(){
			this.show2 = false
			uni.navigateBack()
		},
		getMoney(){
			uni.$u.http.post('/getmoney ').then(res => {
				if (res.code === 1) {
					this.myMoney = res.data
				}
			}).catch((res) => {
				
			})
		},
		ckeck(e) {
			if(!e.id) return this.toast('请选择置顶套餐')
			if(this.myMoney < e.money){
				//余额不足 微信支付
				uni.$u.http.post('/meallist', {
					type:5,
					order_id: this.order_id,
					id:e.id,
					paytype:this.paytype
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						let that = this
						uni.requestPayment({
							appId: res.data.pay.appId,
							nonceStr: res.data.pay.nonceStr,
							package: res.data.pay.package,
							paySign: res.data.pay.paySign,
							signType: res.data.pay.signType,
							timeStamp: res.data.pay.timeStamp,
							success: (e) => {
								that.toast(res.msg)
								that.show2 = false
								setTimeout(() => {
									uni.navigateBack()
								},500)
							},
							fail: (e) => {
								that.$u.toast('支付失败');
							}
						})
					}
				}).catch((res) => {
						
				})
			}else {
				//余额支付
				uni.$u.http.post('/meallist', {
					type:5,
					order_id: this.order_id,
					id:e.id,
					paytype:4
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.toast(res.msg)
						this.show2 = false
						setTimeout(() => {
							uni.navigateBack()
						},500)
					}
				}).catch((res) => {
						
				})
			}
		// 	if(!this.itemid) return this.toast('请选择置顶套餐')
		// 	uni.$u.http.post('/meallist', {
		// 		type:5,
		// 		order_id: this.order_id,
		// 		id: this.itemid
		// 	}).then(res => {
		// 		console.log(res)
		// 		if (res.code == 1) {
		// 			this.toast(res.msg)
		// 			this.show2 = false
		// 			setTimeout(() => {
		// 				uni.navigateBack()
		// 			},500)
		// 		}
		// 	}).catch((res) => {
		
		// 	})
		},
		getcombo() {
			uni.$u.http.post('/meallist',{
				mealtype:5
			}).then(res => {
				if (res.code == 1) {
					this.meal = res.data
				}
			}).catch((res) => {
			})
		},
		toidle(){
			uni.navigateBack()
		},
		getcity(){
			uni.$u.http.post('/index/cityList').then(res => {
				if (res.code === 1) {
					this.cityList = [res.data]
					this.cityList.push(res.data[0].children)
				}
			}).catch((res) => {
						
			})
		},
		changeHandler(e){
			console.log(e,'eeeeeeee')
			const {
		        columnIndex,
		        value,
		        values, // values为当前变化列的数组内容
		        index,
				// 微信小程序无法将picker实例传出来，只能通过ref操作
		        picker = this.$refs.uPicker
		    } = e
		    // 当第一列值发生变化时，变化第二列(后一列)对应的选项
		    if (columnIndex === 0) {
		        // picker为选择器this实例，变化第二列对应的选项
		        picker.setColumnValues(1, this.columnData[index])
		    }
		},
		confirm(e) {
		    console.log('confirm', e)
			this.county = e.value[0].name + e.value[1].name
		    this.show = false
		},
		getcity(){
			uni.$u.http.post('/index/cityList').then(res => {
				if (res.code === 1) {
					this.cityList = [res.data]
					this.cityList.push(res.data[0].children)
				}
			}).catch((res) => {
						
			})
		},
		//二手房详情
		gethouseDetail(id){
			uni.$u.http.post('/recruit/editInfo',{
				id
			}).then(res => {
				if (res.code == 1) {
					this.title = res.data.title
					this.name = res.data.name
					this.mobile = res.data.mobile
					this.description = res.data.description
					this.county = res.data.county
					this.min_salary = res.data.min_salary
					this.max_salary = res.data.max_salary
					this.job_id = res.data.job_id
					
					if(res.data.video){
						this.fileList2 = res.data.video.split(",").map(value => {
							return {
								url: this.oss(value),
								ful: value
							}
						})
					}
					if(res.data.videos){
						this.fileList3 = res.data.videos.split(",").map(value => {
							return {
								url: this.oss(value),
								ful: value
							}
						})
					}
				}
			}).catch((res) => {
			
			})
		},
		issue(){
			if(this.county == '请选择') return uni.$u.toast('请选择城市')
			let video = [];
			this.fileList2.forEach(item => {
				video.push(item.url)
			})
			let videos = [];
			this.fileList3.forEach(item => {
				videos.push(item.url)
			})
			let data = {
				title:this.title,
				job_id:this.job_id,
				description:this.description,
				county:this.county,
				min_salary:this.min_salary,
				max_salary:this.max_salary,
				name:this.name,
				mobile:this.mobile,
				type:this.id ? 'edit' : 'add',
				video:video.join(','),
				videos:videos.join(','),
			}
			if(this.id){
				data.id = this.id
			}
			console.log(data)
			uni.$u.http.post('/recruit/postRecruit',data).then(res => {
				if (res.code == 1) {
					console.log(res,'?????')
					// that.$u.toast(res.msg);
					if(this.id){
						uni.$u.toast(res.msg)
						setTimeout(() => {
							uni.navigateBack()
						},500)
					} else {
						this.order_id = res.data
						this.show2 = true
					}
				}
			}).catch((res) => {
			
			})
		},
		onconfirm1(e) {
		    console.log(e)
			this.job_name = e.selected[0].name
			this.job_id = e.selected[0].id
		},
		getjob(){
			uni.$u.http.post('/recruit/job').then(res => {
				if (res.code == 1) {
					this.range1 = res.data
					this.job_name = this.range1.filter(item => item.id === this.job_id).map(item => item.name).join(',')
				}
			}).catch((res) => {
			
			})
		},
		open() {
			// console.log('open');
		},
		close() {
			this.show2 = false;
			// console.log('close');
		},
		// 删除图片
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1)
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file)
			let fileListLen = this[`fileList${event.name}`].length
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url)
				console.log(result)
				if (result) {
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result.url
					}))
					fileListLen++
				} else {
					this[`fileList${event.name}`].splice(fileListLen, 1)
				}
		
			}
			console.log(this[`fileList${event.name}`])
		},
		uploadFilePromise(url) {
			console.log(url)
			let that = this
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: that.Upload.uploadurl, // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					formData: {
						type: 'image',
						token: uni.getStorageSync('token')
					},
					success: (res) => {
						let data = JSON.parse(res.data)
						if (res.statusCode === 200 && data.code === 1 && data.data) {
							resolve(data.data)
						} else {
							resolve()
						}
					}
				});
			})
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f6f6f6;
}
.info-box {
	width: 622rpx;
	padding: 29rpx 32rpx;
	background: #ffffff;
	border-radius: 16rpx 16rpx 16rpx 16rpx;
	opacity: 1;
	margin: auto;

	.info-each {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;

		.input {
			display: flex;
			align-items: center;
			text-align: right;
			font-size: 30rpx;
			font-weight: 500;
			color: #333333;

			text {
				display: inline-block;
				padding-left: 30rpx;
			}
		}

		image {
			width: 32rpx;
			height: 32rpx;
			position: relative;
			top: 7rpx;
			left: 20rpx;
		}
		.tint {
			font-size: 30rpx;
			font-weight: 500;
			color: #999999;
		}
		
		.pay-box {
			display: flex;
			align-items: center;
			.origin {
				padding: 0 16rpx;
				// width: 202rpx;
				height: 66rpx;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				opacity: 1;
				border: 1rpx solid #F0F0F0;
				font-size: 24rpx;
				font-weight: 500;
				color: #333333;
				margin-left: 16rpx;
				input {
					display: inline-block;
					width: 100rpx;
					position: relative;
					top: 10rpx;
				}
				text {
					font-size: 24rpx;
					font-weight: 500;
					color: #333333;
					.need {
						color: #FA7265;
					}
				}
			}
		}
	}
	.upimg {
		margin-top: 30rpx;
	}

	.wire {
		width: 622rpx;
		height: 1rpx;
		background-color: #f0f0f0;
		margin: auto;
		margin: 30rpx 0;
	}

	.tags-box {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		.tags {
			display: flex;
			margin-top: 24rpx;
			.tag {
				background-color: #f6f6f6;
				font-size: 30rpx;
				padding: 19rpx 48rpx 19rpx 24rpx;
				font-weight: 500;
				color: #333333;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-right: 24rpx;
				image {
					width: 30rpx;
					height: 30rpx;
					position: relative;
					top: 7rpx;
					left: 20rpx;
				}
			}
		}
	}

	.introduce-box {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		.textarea-box {
			padding: 24rpx 0;
			height: 180rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #333333;
			
			textarea {
				height: 180rpx;
			}
		}
	}
}

.cotton {
	height: 160rpx;
}
.btn-box {
	width: 100%;
	position: fixed;
	bottom: 20rpx;

	.btn {
		width: 686rpx;
		height: 98rpx;
		background: #febf4e;
		border-radius: 49rpx 49rpx 49rpx 49rpx;
		opacity: 1;
		margin: auto;
		text-align: center;
		line-height: 98rpx;
		font-size: 30rpx;
		font-weight: 500;
		color: #333333;
	}
}

.popup-box {
	width: 560rpx;
	// height: 914rpx;
	padding-bottom: 32rpx;
	background: #FFFFFF;
	border-radius: 24rpx 24rpx 24rpx 24rpx;
	opacity: 1;
	.pop-title {
		font-size: 32rpx;
		text-align: center;
		padding-top: 60rpx;
		font-weight: bold;
		color: #333333;
	}
	.pop-hint {
		font-size: 24rpx;
		text-align: center;
		padding-top: 16rpx;
		font-weight: 500;
		color: #999999;
	}
	.content {
		width: 432rpx;
		padding: 32rpx;
		// height: 264rpx;
		background: #F6F6F6;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		margin: auto;
		margin-top: 40rpx;
		margin-bottom: 24rpx;
		text {
			font-size: 28rpx;
			font-weight: 500;
			color: #666666;
			line-height: 50rpx;
		}
	}
	.mobile {
		font-size: 48rpx;
		font-weight: bold;
		color: #333333;
		text-align: center;
		padding-top: 16rpx;
	}
	.btn-1 {
		width: 496rpx;
		height: 80rpx;
		background: #FEBF4E;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		text-align: center;
		line-height: 80rpx;
		font-size: 26rpx;
		font-weight: 500;
		color: #333333;
		margin: auto;
		margin-top: 48rpx;
	}
	.btn-2 {
		width: 496rpx;
		height: 80rpx;
		background: #FFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		text-align: center;
		line-height: 80rpx;
		font-size: 26rpx;
		font-weight: 500;
		color: #333333;
		margin: auto;
		margin-top: 24rpx;
		border: 1rpx solid #F0F0F0;
	}
}

.serveBox {
				width: 690rpx;
				border-radius: 20rpx;

				.serve_tit {
					// margin-top: 30rpx;
					text-align: center;
					font-size: 36rpx;
					color: #333333;
					font-weight: bold;
					line-height: 40rpx;
				}
				
				.tc-img {
					width: 600rpx;
					margin: auto;
					margin-top:24rpx;
					image {
						width: 600rpx;
						height: 500rpx;
					}
				}
				
				.serve_cont {
					// margin: 0 30rpx;
					display: flex;
					// flex-wrap: wrap;
					// flex-direction: row;
					
					margin-top: 24rpx;
					overflow: hidden;
					overflow-x: auto;
					white-space: nowrap;

					.serve {
						margin: 30rpx 0;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						margin-right: 20rpx;
						padding: 16rpx 32rpx;
						// width: 190rpx;
						// height: 200rpx;
						box-sizing: border-box;
						border-radius: 20rpx;
						border: 1rpx solid #989898;


						.serve_num {
							margin-bottom: 20rpx;
							font-size: 32rpx;
							font-weight: bold;
							color: #333;
							line-height: 45rpx;
						}

						.serve_hour {
							font-size: 28rpx;
							font-weight: 400;
							color: #323232;
							line-height: 40rpx;
						}
					}

					.active {
						border: 2px solid #FF7A7A !important;
					}

				}
				
				.tc-btn-box {
					width: 560rpx;
					margin: auto;
					margin-top: 20rpx;
					display: flex;
					justify-content: space-between;
					.tc-btn1 {
						width: 220rpx;
						height: 80rpx;
						background-color: #FBBA45;
						border-radius: 10rpx;
						text-align: center;
						line-height: 80rpx;
					}
					.tc-btn2 {
						width: 220rpx;
						height: 80rpx;
						border-radius: 10rpx;
						text-align: center;
						line-height: 80rpx;
						background-color: #9A9A9A;
						color: #FFF;
					}
				}
			}
			
			
			.issue {
					width: 60rpx;
					height: 60rpx;
					background: linear-gradient(180deg, #FECB6F 0%, #FFAE1C 100%);
					border-radius: 0rpx 0rpx 0rpx 0rpx;
					opacity: 1;
					border-radius: 50%;
					font-size: 24rpx;
					font-weight: bold;
					color: #333333;
					padding: 20rpx;
					text-align: center;
					position: fixed;
					right: 32rpx;
					// bottom: 200rpx;
					bottom: 48%;
					z-index: 9;
				}
</style>
